import smtplib
from function.New_report import *
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.header import Header
def SendEail():
    msg=MIMEMultipart()
    smtp_server='smtp.qq.com'
    sender ='1457252030@qq.com'
    password='wpaswqvmizxjficc'  # 发送邮件的授权码
    receivers=['1457252030@qq.com','测试邮箱']
    mail_msg=""" 
                <pre>
                 <br>您好！！</br> 
                 <p>Python 邮件发送测试...可不必理会可不必理会</p><br/>
                 <p><a href="http://www.runoob.com">这是一个链接</a></p> 
                 <br>谢谢！！</br>
                 </pre>
                 """
    mail_body = new_report()
    msg.attach(MIMEText(mail_msg,"html",'utf-8'))
    msg.attach(MIMEText(mail_body,"html",'utf-8'))
    subject='测试报告'
    msg['subject'] = Header(subject,'utf-8')
    msg['from'] = Header('追风<%s>'%sender,'utf-8')
    msg['to'] = Header('<%s>' % receivers,'utf-8')
    # 添加附件 filename可以任意写，写什么名字，邮件中显示什么名字
    sendfile = open('../logs/loging1.logs','rb').read()
    att = MIMEText(sendfile,'base64','utf-8')
    att['Content-Type']='application/octet-stream'
    att['Content-Disposition']="attachment;filename='logs.txt'"
    msg.attach(att)
    try:
        smtpObj=smtplib.SMTP_SSL(smtp_server,465)
        smtpObj.login(sender,password)
        smtpObj.sendmail(sender,receivers,msg.as_string())
        print('mail send success')
    except Exception as e:
        print('mail send failed',e)

SendEail()